<template>
  <div class="stulist" >
        <span class="name">昵称：</span> <span class="nicheng">{{ item.postNickname }}</span> <br>
        <span class="tiezi">帖子：</span> 
        <span><ul>
            <li>
            <span class="title">{{ item.postTitle }}</span> 
            <van-icon name="ellipsis" size="30" @click="Show"/>
                        <van-action-sheet
                          v-model="show"
                          :actions="actions"
                          cancel-text="取消"
                          close-on-click-action
                          @cancel="onCancel"
                          @select="onSelect"
                        /> 
            </li>
        </ul></span>
     </div>
</template>

<script>
import {deletePost} from '@/api/user'
export default {
    data() {
        return {
            active:0,
            value:'',
            stulist:[],
            show: false,
            actions:[{ name: '删除' },{name:'查看'}],
        }
    },
    props: {
    item: {
      type: Object,
      default: () => {
        return {}
      },
    }
  },
  methods:{
    Show(){
        this.show=true
    },
    onCancel() {
     this.$toast('取消')
    },
    onSelect(item) {
        if(item.name=='删除'){
            this.DeleteCommend()
            // this.$toast('删除成功');
        }else if(item.name=='查看'){
            this.lookDetail();
        }
    },


     //删除定义方法
     DeleteCommend(){
        // console.log('要删的评论id',this.item.postId);
        if(this.item.postId==null){
          this.$toast('用户未发布过帖子，无法删除')
          return
        }
        deletePost(this.item.postId)
        .then((res)=>{
          location.reload();
          this.$toast('删除成功');
            // console.log('删除返回响应值',res);
        }).catch((err)=>{
          console.log(err);
        })
    },
    //查看跳转
    lookDetail() {
      const param1 = this.item.postId; 
      const param2 = this.item.postUid; 
      if(param1==null){
          this.$toast('用户未发布过帖子，无法查看')
          return
        }
    //   console.log("传递来的参数",param1,param2);
    this.$router.push(`/pinglun/${param1}/${param2}`);
    }

}
}
</script>

<style lang="less" scoped>

.stulist{
    margin-top: 15px;
    background-color: #f5f7f9;
    border-radius: 20px;
    .name{
        margin-left: 15px;
        font-size: 15px;
        font-weight: 600;
    }
    .nicheng{
        margin-left: 35px;
        font-size: 15px;
        font-weight: 400;
    }
    .tiezi{
        display: block;
        margin-left: 15px;
        margin-top: 20px;
        font-size: 15px;
        font-weight: 600;
    }
    .title{
        display: block;
        width: 80px;
        margin-left: 100px;
        margin-top: -16px;
        font-size: 15px;
        overflow: hiddden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
  }
.van-icon{
    size: 20px;
    margin-left: 15px;
}
.van-icon-ellipsis{
    display: block;
    margin-left: 84.66667vw;
    margin-top: -22px;
}

</style>